import request from '@/utils/request.js';
const state = {
	//首页数据
	homeData: {},
	//存储全部分类的数据
	list:[]
};
const mutations = {
	GETHOMEDATA(state, homeData) {
		state.homeData = homeData
	},
	CATEGORY(state,list){
		state.list = list
	}
};
const actions = {
	//获取首页数据
	async getHomeData({
		state,
		dispatch,
		commit
	}) {
		let result = await request("/getIndexData")
		commit('GETHOMEDATA', result)
	},
	//获取其他分类商品数据
	async categoryList({
		state,
		dispatch,
		commit
	}){
	let result = await request("/getIndexCateList");
	//接口返回全部分类商品的数据 数组里有三个元素
	commit("CATEGORY",result)
	}
};
//简化数据
const getters = {
	//导航数据
	navList(state) {
		return (state.homeData.kingKongModule || {}).kingKongList || []
	},
	//三个小图标数据
	iconList(state) {
		return state.homeData.policyDescList || []
	},
	//组件卡片的数据
	cardList(state) {
		return state.homeData.categoryModule || []
	}
};
//对外暴露小仓库
export default {
	state,
	mutations,
	actions,
	getters
}
